home *** CD-ROM | disk | FTP | other *** search
- Path: kbad.eglin.af.mil!rpi!not-for-mail
- From: richard@moriarty.com (Richard Jason Lyders)
- Newsgroups: comp.sys.mac.oop.misc,comp.sys.mac.programmer.codewarrior,comp.lang.c++,comp.lang.c++.moderated
- Subject: [Q] [enums] class_ID as enum is basically useless? Why not GetClassID()?
- Date: 14 Jan 1996 20:20:47 -0000
- Organization: Moriarty & Associates, Inc.
- Sender: cppmods@netlab.cs.rpi.edu
- Approved: Dietmar.Kuehl@uni-konstanz.de
- Message-ID: <4dboiv$rlm@netlab.cs.rpi.edu>
- NNTP-Posting-Host: netlab.cs.rpi.edu
- X-Original-Date: Sat, 13 Jan 1996 19:53:19 -0600
-
- HELP! Suggestions are MOST WELCOME!
-
- Why would someone use an enum for a class_ID in a class library? Why not
- simply provide a GetClassID() function for each class? That would be so
- much simpler and so much more useful!
-
- I don't seem to be able to use the enum class_ID to find out what class
- an object is because class_ID isn't "virtual" like a function. If you have
- an object of a class that is derived from a base class, and you are
- referencing that object using the base pointer, then class_ID does not
- tell you the class of the object, it tells you the class of the pointer.
- What god is this? I know what class the pointer is because I cast it
- myself! Duh?
-
- This means that I don't seem to be able to create a routine that uses a
- base class as a pointer to any of that base class's derived classes. . .
- because in that routine I need to know exactly what the class_id is of the
- REAL object rather than the class_ID of the base object (which is pretty
- darn obvious because it never changes).
-
- I did not expect to run into this problem. Is this a limitation? an error
- on my part? Is there another way to find out the actual class of an object
- without using a class_ID enum that really will give me the correct
- class_ID?
-
- So , by using an enum . . .whatever you type cast a pointer as. . . that's
- the class ID that you get. . . so it isn't any better than a compiler
- #define as far as I am trying to use it.
-
- If you check out my code example below. . .you will see my confusion as to
- why a class_ID enum would be used . . . and I hope ther is another way of
- finding out an object's actual class ID.
-
- PS: and no, it is not possible to give each class a GetClassID routine
- because I am having this problem with the Metrowerks PowerPlant class
- library and I don't think it is very acceptible to just go around
- changing the inner workings of a class library.
-
- class LPane {
- public:
- enum { class_ID = 'pane' };
- LPane() {};
- ~LPane() {};
- };
-
- class LView : public LPane {
- public:
- enum { class_ID = 'view' };
- LView() {};
- ~LView() {};
- };
-
- void main (void) {
- LPane aPane;
- LView aView;
- LPane * aPanePtr = &aPane;
- LView * aViewPtr = &aView;
- LPane * aPanePtr2 = (LPane*)aViewPtr;
-
- long aPaneClassID = aPanePtr->class_ID; // = 'pane' (obviously)
- long aViewClassID = aViewPtr->class_ID; // = 'view' (obviously)
- long aWhichClassID = aPanePtr2->class_ID; // = 'pane' ********* why?
- **********
- }
-
- /*
- ?
- ___ o _ _ /
- | o \ _ ___| |_ ___ _ _ _| | /"""\
- | /| | __) | o | '_| o | |~'~|
- |_|_\|_\___)_|_|_|_|_| \___| \ - /
- .---------------------------------^----.
- | Richard Jason Lyders Houston, Texas |
- | richard@moriarty.com |
- '-----------------------------OOo----oOO
- |=[]=|
- /_/\_\
- oOO OOo
-
- */
-
- [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
- [ Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm ]
- [ Moderation policy: http://www.connobj.com/cpp/guide.htm ]
- [ Comments? mailto:c++-request@netlab.cs.rpi.edu ]
-